Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable flake8 annotations #3098

Merged
merged 18 commits into from
Nov 5, 2024

Conversation

CoolCat467
Copy link
Member

In this pull request, we enable ruff's flake8-annotations rule.

One of the more major things this rule complains about is missing type annotations on self and cls arguments, so there are a lot of places that got Self and type[Self] annotations added respectfully, as there is not a way to specifically ignore self or cls in particular without missing others.

@CoolCat467 CoolCat467 added the skip newsfragment Newsfragment is not required label Sep 29, 2024
Copy link

codecov bot commented Sep 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.63%. Comparing base (c7801ae) to head (cf7df04).
Report is 19 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3098   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files         122      122           
  Lines       18380    18380           
  Branches     1222     1222           
=======================================
  Hits        18312    18312           
  Misses         47       47           
  Partials       21       21           
Files with missing lines Coverage Δ
src/trio/_channel.py 100.00% <ø> (ø)
src/trio/_core/_instrumentation.py 100.00% <100.00%> (ø)
src/trio/_core/_mock_clock.py 100.00% <100.00%> (ø)
src/trio/_core/_run.py 99.02% <ø> (ø)
src/trio/_dtls.py 97.50% <100.00%> (ø)
src/trio/_file_io.py 100.00% <100.00%> (ø)
src/trio/_highlevel_socket.py 100.00% <100.00%> (ø)
src/trio/_repl.py 100.00% <100.00%> (ø)
src/trio/_socket.py 100.00% <100.00%> (ø)
src/trio/_subprocess_platform/__init__.py 100.00% <100.00%> (ø)
... and 12 more

Copy link
Contributor

@TeamSpen210 TeamSpen210 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the self/cls issue is because this is enabling the deprecated ANN101/ANN102 rules. Those should be disabled. Also, I really don't see the point anyway in running any of our linters on notes-to-self. Those are just historical test/example scripts, they're not supposed to be robust or anything. It just produces churn...

@CoolCat467
Copy link
Member Author

Actually, the self/cls issue is because this is enabling the deprecated ANN101/ANN102 rules. Those should be disabled. Also, I really don't see the point anyway in running any of our linters on notes-to-self. Those are just historical test/example scripts, they're not supposed to be robust or anything. It just produces churn...

Did a force push basically redoing everything, much easier than manually undoing adding self everywhere

src/trio/_tests/test_util.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
src/trio/_core/_concat_tb.py Outdated Show resolved Hide resolved
def create_pipe_from_child_output():
def create_pipe_from_child_output() -> tuple[PipeReceiveStream, int]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a mypy setting for catching this as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are referring to disallow_incomplete_defs and check_untyped_defs, those two are already enabled for Trio.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant disallow_untyped_defs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disallow_untyped_defs is also already enabled

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then why did this not get caught by mypy previously??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure

src/trio/_tests/test_highlevel_open_tcp_stream.py Outdated Show resolved Hide resolved
src/trio/_tests/test_ssl.py Outdated Show resolved Hide resolved
src/trio/_tests/test_ssl.py Outdated Show resolved Hide resolved
CoolCat467 and others added 2 commits October 16, 2024 20:58
Co-authored-by: John Litborn <11260241+jakkdl@users.noreply.github.com>
@jakkdl
Copy link
Member

jakkdl commented Oct 17, 2024

Actually, the self/cls issue is because this is enabling the deprecated ANN101/ANN102 rules. Those should be disabled. Also, I really don't see the point anyway in running any of our linters on notes-to-self. Those are just historical test/example scripts, they're not supposed to be robust or anything. It just produces churn...

tbh, is there any reason to keep them around at all anymore? We could dump them in a gist and save a link somewhere if we want to save them somewhere (other than in the git history)

@TeamSpen210
Copy link
Contributor

Could create a git tag to mark which commit is is with the last version.

@jakkdl jakkdl mentioned this pull request Oct 20, 2024
Comment on lines +167 to +168
# Don't check annotations in notes-to-self
'notes-to-self/*.py' = ['ANN001', 'ANN002', 'ANN003', 'ANN201', 'ANN202', 'ANN204']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whichever is merged latest of this and #3117 can remove these lines.

CoolCat467 added a commit to CoolCat467/trio that referenced this pull request Oct 27, 2024
              agreed. disable ANN401 for now and enable `disallow_any_explicit` in a separate PR. Possibly same for `disallow_untyped_defs`.

_Originally posted by @jakkdl in python-trio#3098 (comment)
@CoolCat467
Copy link
Member Author

Planning on merging this in a day or two unless anyone has any other comments.

@CoolCat467 CoolCat467 merged commit 0ee5a69 into python-trio:main Nov 5, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip newsfragment Newsfragment is not required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants